<div class="pull-right" >
  <a href="?/admin/page/add/<?php echo $upid ?>/" class="btn btn-primary"  ><i class="icon ion-md-add-circle"></i> 添加页面 </a>
</div>
<div class="breadcrumb">
  <span class="layui-breadcrumb crumbs">
    <a href="?/admin/page/"><?php echo empty(seg(3))?"<cite>":"" ?>页面</a>
    <?php foreach ($uper as $k => $v) { ?>
      <a href="?/admin/page/<?php echo $k ?>"><?php echo $k==seg(3)?"<cite>":"" ?><?php echo $v ?></a>
    <?php } ?>
  </span>
</div>
<input type="hidden" id="upid" value="<?php echo empty(seg(3))?'0':seg(3) ?>" />
<table class="table">
  <thead>
    <tr>
      <th width="25" ><input type="checkbox" /></th><th>标题</th><th>页面</th><th>更新日期</th><th>排序</th><th>操作</th>
    </tr>
  </thead>
  <?php foreach($records as $r){ ?>
  <?php if($r['meta']['type']=="list"): ?>
  <tr id="r<?php echo $r['uuid'] ?>" title="line<?php echo ++$i ?>">
    <td><input type="checkbox" name="pids" value="<?php echo $r['uuid'] ?>" ></td>
    <td>  <a href="?/admin/page/<?php echo $r['uuid'] ?>/"> <img src="/static/folder.png"><?php echo $r['title'] ?></a></td>
    <td><a href="?/admin/page/edit/<?php echo $r['uuid'] ?>/"> <?php echo $r['name'] ?></a> </td>
    <td><?php echo date('Y-m-d',$r['update_date']) ?></td>
    <td><input type="text" size="5" data-id="<?php echo $r['uuid'] ?>" value="<?php echo $r['order'] ?>" onchange="change_order(this)" /></td>
    <td class="ions" >
      <a href="?/admin/page/<?php echo $r['uuid'] ?>/" ><img src="/static/folder.png"></a>
      <a href="?/admin/page/edit/<?php echo $r['uuid'] ?>/" ><img src="/static/edit.png"></a>
      <a href="javascript:bdel('?/admin/page/del/<?php echo $r['uuid'] ?>/', 'r<?php echo $r['uuid'] ?>');" ><img src="/static/delete.png"></a>
      <a href="http://<?php echo $site['domain'] ?>/p/<?php echo $r['name'] ?>/" target=_blank > <img src="/static/search.png" alt="查阅" > </a>
    </td>
  </tr>
  <?php endif ?>
  <?php } ?>
  <?php foreach($records as $r){ ?>
  <?php if($r['meta']['type']!="list"): ?>
  <tr id="r<?php echo $r['uuid'] ?>" title="line<?php echo ++$i ?>">
    <td><input type="checkbox" name="pids" value="<?php echo $r['uuid'] ?>" ></td>
    <td><a href="?/admin/page/edit/<?php echo $r['uuid'] ?>/"><?php echo $r['title'] ?></a> </td>
    <td><a href="?/p/<?php echo $r['uuid'] ?>/" target=_blank ><?php echo $r['name'] ?></a> </td>
    <td><?php echo date('Y-m-d',$r['update_date']) ?></td>
    <td><input type="text" size="5"  data-id="<?php echo $r['uuid'] ?>" value="<?php echo $r['order'] ?>" onchange="change_order(this)" /></td>
    <td class="ions" >
      <a href="?/admin/page/edit/<?php echo $r['uuid'] ?>/" ><img src="/static/edit.png"></a>
      <a href="javascript:bdel('?/admin/page/del/<?php echo $r['uuid'] ?>/', 'r<?php echo $r['uuid'] ?>');" ><img src="/static/delete.png"></a>
      <a href="http://<?php echo $site['domain'] ?>/p/<?php echo $r['name'] ?>/" target=_blank > <img src="/static/search.png" alt="查阅" > </a>
    </td>
  </tr>
  <?php endif ?>
  <?php } ?>
</table>
<button onclick="cut();" >剪切</button>
<button onclick="paste();" >粘贴</button>


<script>

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
} 


function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
         }
         if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
         }
     }
    return "";
} 


function getPids()
{
  var pids = [];
  $('input[name=pids]:checked').each(function(){pids.push($(this).val());});
  //console.log(pids);
  return pids;
}

function cut()
{
  pids = getPids();
  setCookie('cut',pids.join(),1);
  alert("剪切成功，进入目标目录黏贴即可移动页面");
}

function paste()
{
  pids = getCookie('cut');
  upid = $('#upid').val();
  $.ajax({
      type:'POST',
      url: '?/admin/paste/',
      data : {upid:upid,pids:pids}
  });
  location.reload();
}

function elem_change(elem1, elem2) {
  line1 = $('tr[title='+elem1+']');
  id1 = line1.attr('id');
  line2 = $('tr[title='+elem2+']');
  id2 = line2.attr('id');
  temp = line1.html();
  line1.html(line2.html());
  line2.html(temp);
  line1.attr('id', id2);
  line2.attr('id', id1);
}

function change_order(a){
  $.ajax({
      type:'POST',
      url: '?/admin/change_order/',
      data : {id:a.dataset.id,order:a.value}
  });
}


</script>
